<?php
class koudai_orderModel extends model{
	public $base;
	public $oc_where;
	public function __construct(&$base){
		parent::__construct($base);
		$this->base=$base;
		$this->table="koudai_order";
		$this->oc_where=M('login')->userid?" (userid=".M('login')->userid." or oc_ssid='".OC_SSID."') ":"oc_ssid='".OC_SSID."' ";
	}
	
	
	public function getGzProduct($userid,$fenqi=1){
		 
		
		if($fenqi==1){
			
			$oids=M("koudai_order")->selectCols(array(
				"where"=>"userid=".$userid." AND fenqi=$fenqi AND isdz>0 AND isadd=0",	
				"fields"=>"order_id"
			));
		}elseif($fenqi==2){
		 
			$sushe=M("sushe_user")->selectOne(array(
				"where"=>" userid=".$userid,
				"fields"=>" sushe"
			));
			 
			if(!$sushe){
				return false;
			}
			
			$oids=M("koudai_order")->selectCols(array(
				"where"=>"  fenqi=$fenqi AND susheid=".$sushe." AND fenqi=$fenqi AND isdz>0 AND isadd=0",	
				"fields"=>"order_id"
			));
			
			 
		}else{
			return false;
		}
		
	 	$p=array();
		if($oids){
			$pros= M("koudai_order_product")->select(array("where"=>"order_id in("._implode($oids).")"));
			 
			if($pros){
				foreach($pros as $v){
					if(!$v['gznum'] && !$v['jsnum'] && !$v['thnum']){
						$v['gznum']=$v['amount'];
						if(isset($p[$v['productid']])){
							$p[$v['productid']]['gznum'] +=$v['gznum'];
						}else{
							$p[$v['productid']]=$v;
						}
					}else{
						if(isset($p[$v['productid']])){
							$p[$v['productid']]['gznum'] +=$v['gznum'];
						}else{
							$p[$v['productid']]=$v;
						}

					}
					$money += $v['gznum']*$v['price'];
				}
			}
			
			return array(
				"oids"=>$oids,
				"money"=>$money,
				"products"=>$p
			);
		}
		 
	}
	
	public function id_list($option){
		$da=$this->select($option);
		$data=array();
		if($da){
			foreach($da as $v){
				$data[$v['order_id']]=$v;
			}
		}
		return $data;
	}
	 
	
	
	
	
}

?>